﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure.StorageClient;
using System.ComponentModel.DataAnnotations;
using System.Data.Services.Common;
using System.ComponentModel;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class contains a group of users
    /// 
    /// RowKey = ID of the group.
    /// PartionKey = ID of the group.
    /// </summary>
    public class Group : BasicDataModel
    {
        #region Fields
        private IList<User> members;
        private IList<Message> mailbox;
        private IList<Event> events;
        private IList<Phrase> greetingsboard;
        private IList<Post> posts;
        private IList<Event> nextevents;
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="Group"/> class.
        /// </summary>
        public Group()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Group"/> class.
        /// </summary>
        /// <param name="groupOwner">The group owner.</param>
        /// <param name="identifier">The identifier.</param>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="description">The description.</param>
        /// <param name="website">The website.</param>
        /// <param name="site">The site.</param>
        /// <param name="avatar">The avatar.</param>
        public Group(string groupOwner, string alias,  string groupName, string description, string website, string site, string avatar)
        {
            RowKey = alias;
            PartitionKey = RowKey;
            Owner = groupOwner;
            Description = description;
            Alias = alias;
            Name = groupName;
            Website = website;
            Site = site;
            Avatar = avatar;
        }

        /// <summary>
        /// Gets the short name.
        /// </summary>
        /// <returns>Short name of the group.</returns>
        public String GetShortName()
        {
            if (Alias.Length <= 58)
            {
                return Alias;
            }
            else
            {
                return String.Format("{0}...", Alias.Substring(0, 58));
            }
        }

        /// <summary>
        /// Gets or sets the group name.
        /// </summary>
        /// <value>The group name.</value>
        [Required(ErrorMessage = "Debe introducir un nombre.")]
        [DisplayName("Nombre")]
        public String Name { get; set; }
        /// <summary>
        /// Gets or sets the avatar url.
        /// </summary>
        /// <value>The avatar url.</value>
        [DisplayName("Avatar")]
        public String Avatar { get; set; }
        /// <summary>
        /// Get or sets the group owner name.
        /// </summary>
        [DisplayName("Creador")]
        public string Owner { get; set; }
        /// <summary>
        /// Gets or sets the description of the group.
        /// </summary>
        /// <value>The group's description.</value>
        [Required(ErrorMessage = "Debe introducir una descripción.")]
        [DisplayName("Descripción")]
        public string Description { get; set; }
        /// <summary>
        /// Gets or sets the name of the group.
        /// </summary>
        /// <value>The group's name.</value>
        [Required(ErrorMessage = "Debe introducir un alias.")]
        [DisplayName("Alias")]
        public string Alias 
        {
            get { return this.RowKey; }
            set { this.RowKey = value; }
        }
        /// <summary>
        /// Gets or sets the website of the group.
        /// </summary>
        /// <value>The group's website.</value>
        [DisplayName("Página web")]
        public string Website { get; set; }
        /// <summary>
        /// Gets or sets the site of the group.
        /// </summary>
        /// <value>The group's site.</value>
        [Required(ErrorMessage = "Debe introducir una localización.")]
        [DisplayName("Dirección")]
        public string Site { get; set; }
        /// <summary>
        /// Gets or sets the ID of the group.
        /// </summary>
        /// <value>The ID.</value>
        public string ID
        {
            get { return this.RowKey; }
            set { }
        }
    }
}
